<?php
/**
 * Created by PhpStorm.
 * User: buluota
 * Date: 15-1-16
 * Time: 下午12:33
 */
class ExternalService extends BaseService
{
    private static $self = NULL;

    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }

        return self::$self;
    }

    private $mServiceData   = NULL;


    private function __construct()
    {
        $this->mServiceData     = new ServiceDataModel();
    }

    /** 获取汽车服务网点数据
     * @param $url
     * @return mixed
     */
    public function getCarServiceData($url)
    {
        $client = REST_Client::instance();
        $client->setMethod(REST_Client::METHOD_GET);
        $client->setApi($url);
        $client->go();
        $body = $client->getBody();
        return json_decode($body,true);
    }

    /**
     * 汽车服务网点数据入库
     * @param $data
     * @return int
     */
    public function insertServiceData($data)
    {
        $collection = array();
        foreach($data as $b)
        {
            $collection[] = array('service_data' => json_encode($b));
        }
        return $this->mServiceData->insert($collection);
    }


}